package sy.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import sy.pageModel.BaseEntity;
import sy.pageModel.Json;
import sy.pageModel.SessionInfo;
import sy.pageModel.UserAction;
import sy.service.UserActionServiceI;
import sy.util.ResourceUtil;

import java.util.List;

public class BaseController {
	
	@Autowired
	protected UserActionServiceI userActionService;

	protected void logUserAction(HttpSession session, String action, String details) {
		try {
			SessionInfo sessionInfo = (SessionInfo)session.getAttribute(ResourceUtil.getSessionInfoName());
			UserAction userAction = new UserAction(sessionInfo);
			userAction.setAction(action);
			userAction.setDetails(details);
			userActionService.add(userAction);
		} catch(Exception e) {
			e.printStackTrace();
			System.out.println("添加用户操作日志失败！");
		}
	}

	protected String findOption(List<BaseEntity> list){
		String res="";
		for (BaseEntity entity:list) {
			res+="<option value='"+entity.getId()+"'>"+"["+entity.getId()+"]"+entity.getName()+"</option>";
		}
		return res;
	}

}
